<div class="layuimini-main" id="admin-edit">

    <div class="layui-form layuimini-form" lay-filter="admin_edit_div_filter">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="userName" disabled lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
                <tip>填写自己管理账号的名称。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">身份</label>
            <div class="layui-input-block">
                <input type="radio" id="adminType1" name="role" value="Admin" title="管理员" checked="">
                <input type="radio" id="adminType2" name="role" value="User" title="操作员">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码：</label>
            <div class="layui-input-block">
                <input type="password" autocomplete='off' name="userPassword"  placeholder="请输入密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">手机</label>
            <div class="layui-input-block">
                <input type="number" name="phone" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'faceAPI'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        var faceAPI = layui.faceAPI;
        faceAPI.AdminEditPageResult = null;
        var editdata = faceAPI.AdminEditPage;
        /*        $("#admin-edit [name=userName]").val(editdata.userName).attr("disabled", "disabled");*/

        form.val("admin_edit_div_filter", editdata);

        //$("#admin-edit [name=phone]").val(editdata.phone);
        //if (editdata.role == 'User')
        //    $("#admin-edit #adminType2").prop("checked", true);
        
        //$("#admin-edit [name=userName]").attr("userid", editdata.userID);


        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData = data.field;
            delete postData.userName;
            postData.userID = editdata.userID;
            faceAPI.Ajax({
                type: 'Post',
                data: postData,
                url: '/api/User/Update',
                success: function (result) {
                    if (result.result == false) {
                        layer.alert(result.error, { icon: 2 });
                    }
                    else {
                        result.content = postData;
                        faceAPI.AdminEditPageResult = result;
                        layer.close(parentIndex);
                    }

                }
            });



            return false;
        });

    });


</script>